﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using trunk.Views;

namespace trunk
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : NavigationWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            CommandBindings.Add(new CommandBinding(MainWindow.GoBackCommand,GoBackExecuted,GoBackCanExecute));
            CommandBindings.Add(new CommandBinding(MainWindow.GoBackMainCommand,GoBackMainExecuted,GoBackMainCanExecute));
        }

        //public RoutedCommand 


        private void EnterButton_Click(object sender, RoutedEventArgs e)
        {
            Console.WriteLine(" enter main demo ... ");
            MessageBox.Show(" enter main demo  ... ");
        }

        #region 返回主页按钮
        public static RoutedCommand GoBackCommand = new RoutedCommand();

        public void GoBackExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            this.NavigationService.GoBack();            
            e.Handled = true;
        }

        public void GoBackCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }
        #endregion

        #region 返回主页按钮
        public static RoutedCommand GoBackMainCommand = new RoutedCommand();

        public void GoBackMainExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            while (this.NavigationService.CanGoBack)
            {
                this.NavigationService.RemoveBackEntry();
            }            
            MainPage mainPage = new MainPage();
            this.NavigationService.Navigate(mainPage);
            e.Handled = true;
        }

        public void GoBackMainCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }
        #endregion
    }
}
